﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FbKPI.Facade;
using FbKPI.Model;

namespace FBKPI.Forms
{
    public partial class KPIAssignDetailForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int ID = Convert.ToInt16(Request.QueryString["ID"]);
                if (ID != 0)
                {
                    KPIAssignDetailFacade df = new KPIAssignDetailFacade();
                    KPIAssignDetail KPIs = df.GetKPIAssignDetailByID(ID);

                    if (KPIs != null)
                    {
                        txt_id.Text = KPIs.ID.ToString();
                        chk_active.Checked = KPIs.isActive;
                        chk_weightenableflag.Checked = KPIs.WeightEnableFlag;
                        chk_uomenableflag.Checked = KPIs.UoMEnableFlag;
                        txt_uom.Text = KPIs.UoM == null ? "" : KPIs.UoM.Description;
                        txt_uomid.Value = KPIs.UoM == null ? "" : KPIs.UoM.ID.ToString();
                        txt_uommax.Text = KPIs.UoMDetailMax == null ? "" : KPIs.UoMDetailMax.Description;
                        txt_uommaxid.Value = KPIs.UoMDetailMax == null ? "" : KPIs.UoMDetailMax.ID.ToString();
                        txt_uommin.Text = KPIs.UoMDetailMin == null ? "" : KPIs.UoMDetailMin.Description;
                        txt_uomminid.Value = KPIs.UoMDetailMin == null ? "" : KPIs.UoMDetailMin.ID.ToString();
                        txt_kpi.Text = KPIs.KPI == null ? "" : KPIs.KPI.Description;
                        txt_kpiid.Value = KPIs.KPI == null ? "" : KPIs.KPI.ID.ToString();
                        txt_kpiassign.Text = KPIs.KPI == null ? "" : KPIs.KPIAssign.RGM.Description.ToString() + (KPIs.KPIAssign.Location == null ? "" : " || " + KPIs.KPIAssign.Location.Description + (KPIs.KPIAssign.SubBranch == null ? "" : " || " + KPIs.KPIAssign.SubBranch.Description));
                        txt_kpiassignid.Value = KPIs.KPI == null ? "" : KPIs.KPIAssign.ID.ToString();
                        txt_employee.Text = KPIs.Employee == null ? "" : KPIs.Employee.FirstName + ' ' + KPIs.Employee.LastName;
                        txt_employeeid.Value = KPIs.Employee == null ? "" : KPIs.Employee.ID.ToString();
                        txt_weight.Text = KPIs.Weight.ToString();
                        txt_polarization.Text = KPIs.Polarization;
                        txt_manualcalculation.Text = KPIs.ManualCalculation.ToString();
                        txt_lastmodifieddate.Text = KPIs.LastModifiedDate == null ? "" : Convert.ToDateTime(KPIs.LastModifiedDate).ToShortDateString();
                        txt_lastmodifiedby.Text = KPIs.LastModifiedBy;
                        txt_createdate.Text = KPIs.CreateDate == null ? "" : Convert.ToDateTime(KPIs.CreateDate).ToShortDateString();
                        txt_createby.Text = KPIs.CreateBy;
                    }
                }
                else
                {
                    txt_id.Text = "0";
                }

                if (txt_id.Text == "0") btn_delete.Visible = false;
            }
        }
    }
}